﻿using System.Collections.Generic;

using UnityEngine;
using UnityEngine.Events;

namespace YuoTools
{
    public class YuoAI : MonoBehaviour
    {
        public Dictionary<string, List<AINode>> All = new Dictionary<string, List<AINode>>();
        public AINode NowSate = new AINode();
        private string tempstr1;
        private int tempint1;

        private void Update()
        {
            tempstr1 = NowSate.name;
            if (All.ContainsKey(tempstr1))
            {
                tempint1 = 0;
                foreach (var item in All[tempstr1])
                {
                    Temp.Int = item.rotate();
                    if (Temp.Int > tempint1)
                    {
                        tempint1 = Temp.Int;
                        NowSate = item;
                    }
                }
                if (tempint1 == 0)
                {
                    NowSate.updateAction?.Invoke();
                }
                else
                {
                    NowSate.action?.Invoke();
                }
            }
        }

        public void Add(string now, string next, IntAction rotate)
        {
            if (!All.ContainsKey(now))
            {
                All.Add(now, new List<AINode>());
            }
            All[now].Add(new AINode() { name = next, rotate = rotate, });
        }

        public class AINode
        {
            public string name = "";
            public IntAction rotate;
            public UnityAction action;
            public UnityAction updateAction;
        }
    }
}